package club.baibin0558.jstudy.core.utils;

import java.util.List;

/**
 * API响应
 * @param <T>
 */
public class ApiResult<T> {
    private Integer code = 200;
    private String msg = "成功";
    private T data;
    private List<T> dataList;

    public ApiResult(Integer code) {
        this.code = code;
    }

    public ApiResult(String msg) {
        this.msg = msg;
    }

    public ApiResult(T data) {
        this.data = data;
    }

    public ApiResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ApiResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ApiResult(Integer code, String msg, T data, List<T> dataList) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.dataList = dataList;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public List<T> getDataList() {
        return dataList;
    }

    public ApiResult() {
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }
    public static final ApiResult<?> success() {
        return new ApiResult<Object>();
    }
    public static final ApiResult<?> success(String msg) {
        return new ApiResult<Object>(msg);
    }
    public static final ApiResult<?> success(Object data) {
        return new ApiResult<Object>(data);
    }
    public static final ApiResult<?> success(List<?> data) {
        return new ApiResult<Object>(data);
    }
    public static final ApiResult<?> success(int code,String msg) {
        return new ApiResult<Object>(code, msg);
    }
    public static final ApiResult<?> fail(int code,String msg) {
        return new ApiResult<Object>(code, msg);
    }
    public static final ApiResult<?> fail(String msg) {
        return new ApiResult<Object>(500, msg);
    }
}
